package com.mywang.weitravel.modules.find;

import com.mywang.weitravel.base.BasePresenter;
import com.mywang.weitravel.model.FindDetailResponse;
import com.mywang.weitravel.net.RetrofitHelper;
import com.mywang.weitravel.net.RxSchedulers;
import com.mywang.weitravel.net.VObserver;

import io.reactivex.disposables.Disposable;

public class FindDetailPresenter extends BasePresenter<FindDetailContract.View> implements FindDetailContract.Presenter {

    public FindDetailPresenter(FindDetailContract.View view) {
        super(view);
    }

    @Override
    public void getFindDetail(String findId) {
        RetrofitHelper.getInstance().getServer()
                .getFindDetail(findId)
                .compose(RxSchedulers.applySchedulers())
                .as(bindToLife())
                .subscribe(new VObserver<FindDetailResponse>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        super.onSubscribe(d);
                        mView.showLoading();
                    }

                    @Override
                    protected void onSuccess(FindDetailResponse findDetailResponse) {
                        mView.getFindDetailSuccessful(findDetailResponse);
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void likeFind(String findId) {
        RetrofitHelper.getInstance().getServer()
                .likeFind(findId)
                .compose(RxSchedulers.applySchedulers())
                .as(bindToLife())
                .subscribe(new VObserver<Object>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        super.onSubscribe(d);
                        mView.showLoading();
                    }

                    @Override
                    protected void onSuccess(Object object) {
                        mView.likeFindSuccessful();
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                        mView.hideLoading();
                    }
                });
    }
}
